﻿using System;
using FireStarterModeller.BO;
using Habanero.Base;
using Habanero.Testability;

namespace FireStarterModeller.Test.BO
{
    public class TestUtilsDMUniqueConstraint
    {
        private readonly static BOTestFactory<DMUniqueConstraint> _factory = GetTestFactory();

        public static BOTestFactory<DMUniqueConstraint> GetTestFactory()
        {
            return BOTestFactoryRegistry.Instance.Resolve<DMUniqueConstraint>();
        }
        /// <summary>
        /// Creates a new saved DMUniqueConstraint with a random value assigned to every property
        /// </summary>
        public static DMUniqueConstraint CreateSavedDMUniqueConstraint()
        {
            DMUniqueConstraint dMUniqueConstraint = CreateUnsavedValidDMUniqueConstraint();
            dMUniqueConstraint.Save();
            return dMUniqueConstraint;
        }

        /// <summary>
        /// Creates a new unsaved DMUniqueConstraint with a random value assigned to every property
        /// </summary>
        public static DMUniqueConstraint CreateUnsavedValidDMUniqueConstraint()
        {
            return CreateUnsavedValidDMUniqueConstraint(null);
        }

        /// <summary>
        /// Creates a new unsaved DMUniqueConstraint with a random value assigned to every property
        /// </summary>
        public static DMUniqueConstraint CreateUnsavedValidDMUniqueConstraint(DMClass dmClass)
        {
            DMUniqueConstraint dMUniqueConstraint = _factory.CreateDefaultBusinessObject();
            if (dmClass == null)
            {
                dMUniqueConstraint.ClassID = TestUtilsShared.CreateSavedDMClass().ClassID;
            }
            else
            {
                dMUniqueConstraint.Class = dmClass;
            }
            _factory.UpdateCompulsoryProperties(dMUniqueConstraint);
/*            dMUniqueConstraint.Message = TestUtilsShared.GetRandomString();
            dMUniqueConstraint.IgnoreIfNull = TestUtilsShared.GetRandomBoolean();
            dMUniqueConstraint.UniqueConstraintName = TestUtilsShared.GetRandomString();
            dMUniqueConstraint.Generated = TestUtilsShared.GetRandomBoolean();
            dMUniqueConstraint.MappedAlternateKeyID = Guid.NewGuid();*/
            return dMUniqueConstraint;
        }
	    
        /// <summary>
        /// Creates a new unsaved DMUniqueConstraint where all properties are null, except ID properties
        /// and those with default values.  If there are compulsory properties without
        /// defaults, saving the object will throw an exception.
        /// </summary>
        public static DMUniqueConstraint CreateUnsavedDefaultDMUniqueConstraint()
        {
            DMUniqueConstraint dMUniqueConstraint = new DMUniqueConstraint();
            return dMUniqueConstraint;
        }

        public static DMUniqueConstraint CreateUniqueConstraint(IDMClass dmClass, params IDMProperty[] ucProps)
        {
            DMUniqueConstraint uniqueConstraint = CreateUniqueConstraint(dmClass);
            foreach (DMProperty ucProp in ucProps)
            {
                uniqueConstraint.UniqueConstraintProperties.Add(new DMUniqueConstraintProperty { Property = ucProp });
            }
            return uniqueConstraint;
        }

        public static DMUniqueConstraint CreateUniqueConstraint(IDMClass dmClass)
        {
            var dmUniqueConstraint = new DMUniqueConstraint { Class = (DMClass) dmClass };
            dmUniqueConstraint.UniqueConstraintName = TestUtilsShared.GetRandomString();
            return dmUniqueConstraint;
        }
    }
    // ReSharper disable UnusedMember.Global
    //This is used by the BOTestRegistry to autoregister this solution Factory.
/*    public class BOTestFactoryUniqueConstraint : BOTestFactory<DMUniqueConstraint>
    {
        public BOTestFactoryUniqueConstraint(DMUniqueConstraint constraint)
            : base(constraint)
        {
        }

        public BOTestFactoryUniqueConstraint()
        {
        }

        public override void UpdateCompulsoryProperties(IBusinessObject businessObject)
        {
            base.UpdateCompulsoryProperties(businessObject);
        }
    }*/
    // ReSharper restore UnusedMember.Global
}